﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SWIRL
{
    public class AccelerometerDataArray
    {
        public List<AccelerometerDataStruct> accelerometerData = new List<AccelerometerDataStruct>();

        /// <summary>
        /// Add accelerometer values to the array
        /// Input object should be AcceletometerDataStruct
        /// </summary>
        /// <param name="ad"></param>
        public void AddAccelerometerData(AccelerometerDataStruct ad)
        {

            accelerometerData.Add(ad);

        }

        /// <summary>
        /// Method returns whole AccelerometerDataStruct struct
        /// </summary>
        /// <returns></returns>
        public List<AccelerometerDataStruct> GetAccelerometerData()
        {
            return accelerometerData;
        }

        /// <summary>
        /// Method returns refined 2D array with only selected axis values with time stamps
        /// </summary>
        /// <param name="axis"></param>
        /// <returns></returns>
        public List<TimeAndAxisValue> GetAccelerometerData(Axis axis)
        {
            List<TimeAndAxisValue> timeAndAxisValue = new List<TimeAndAxisValue>();
            TimeAndAxisValue taValue = new TimeAndAxisValue();


            if (axis == Axis.xAxisValue)
            {
                for (int i = 0; i < accelerometerData.Count; i++)
                {
                    taValue.dateTime = accelerometerData[i].dateTime;
                    taValue.axisValue = accelerometerData[i].xAxisValue;
                    timeAndAxisValue.Add(taValue);
                }

            }


            if (axis == Axis.yAxisValue)
            {
                for (int i = 0; i < accelerometerData.Count; i++)
                {
                    taValue.dateTime = accelerometerData[i].dateTime;
                    taValue.axisValue = accelerometerData[i].yAxisValue;
                    timeAndAxisValue.Add(taValue);
                }
            }
            if (axis == Axis.zAxisValue)
            {
                for (int i = 0; i < accelerometerData.Count; i++)
                {
                    taValue.dateTime = accelerometerData[i].dateTime;
                    taValue.axisValue = accelerometerData[i].zAxisValue;
                    timeAndAxisValue.Add(taValue);
                }
            }


            return timeAndAxisValue;
        }



        public void CleanupArray()
        {
            accelerometerData.Clear();
        }

    }
}
